﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;
using prjKQXS_DLL;
using prjKQXS_DLL.Ve_so;

namespace prjKQXS_UI.Boc
{
    public partial class frmInboc5 : DevExpress.XtraEditors.XtraForm
    {
        public frmInboc5()
        {
            InitializeComponent();
        }
        private void frmInboc5_Load(object sender, EventArgs e)
        {
            deNgay.DateTime = DateTime.Today;
            BienTc.denngay = (DateTime)clsCommon.Parse(deNgay.Text, 4);
            Loadphochutich();           
        }

        private void Loadphochutich()
        {
            SqlConnection conn = new SqlConnection(BienTc.connString);
            DataTable dt = new DataTable();
            try
            {
                txtgiave.Text = "5000";
                SqlDataAdapter da = new SqlDataAdapter("select Tenhoidong as TEN, * from DMHOIDONG where isPublic = 1", conn);
                da.Fill(dt);
                cmbchutich.Properties.DataSource = dt;
                cmbchutich.ItemIndex = 0;
                cmbsotaichinh.Properties.DataSource = dt;
                cmbsotaichinh.ItemIndex = 3;
                cmbthanhtra.Properties.DataSource = dt;
                cmbthanhtra.ItemIndex = 4;
                cmbcongan.Properties.DataSource = dt;
                cmbcongan.ItemIndex = 5;
                cmbsotuphap.Properties.DataSource = dt;
                cmbsotuphap.ItemIndex = 6;
                cmbmattran.Properties.DataSource = dt;
                cmbmattran.ItemIndex = 7;
                cmbcongty.Properties.DataSource = dt;
                cmbcongty.ItemIndex = 2;
                cmbthuky.Properties.DataSource = dt;
                cmbthuky.ItemIndex = 8;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }

        private void btndong_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private DMVETT_DAL dmcanbo_dal = new DMVETT_DAL();
        private void Luuhoidong()
        {
            try
            {
                DMVETT dmvett = new DMVETT();
                dmvett.Kyhieu = txtkyhieu.Text;
                dmvett.Giave = 10000;
                dmvett.Ngaymothuong = (DateTime)clsCommon.Parse(deNgay.Text, 4);
                dmvett.Pchutich = cmbchutich.Text;
                dmvett.Congty = cmbcongty.Text;
                dmvett.Sotaichinh = cmbsotaichinh.Text;
                dmvett.Sotuphap = cmbsotuphap.Text;
                dmvett.Congantinh = cmbcongan.Text;
                dmvett.MattranTQ = cmbmattran.Text;
                dmvett.ThanhtranNN = cmbthanhtra.Text;
                dmvett.Thuky = cmbthuky.Text;
                dmcanbo_dal.InsertDMVE(dmvett);
            }
            catch
            { 
            }
        }

        private void btnquayso_Click(object sender, EventArgs e)
        {
            BienTc.denngay = (DateTime)clsCommon.Parse(deNgay.Text, 4);
            BienTc.KyHieuVe = txtkyhieu.Text.ToString().Trim();
            BienTc.GiaVe = (Int32)clsCommon.Parse(txtgiave.Text, 0);
            if (BienTc.KyHieuVe.Length > 4 || BienTc.KyHieuVe.Length == 0)
            {
                clsCommon.MsgBox("Ký hiệu vé bóc sai, bạn hãy sửa lại", 0);
                txtkyhieu.Focus();
            }
            else
            {
                if ((Int32)clsCommon.Parse(txtgiave.Text, 0) == 2000)
                {
                    Luuhoidong();
                    frmQuayveboc2 frm = new frmQuayveboc2();
                    frm.ShowDialog();
                }
                else
                {
                    Luuhoidong();
                    frmQuayveboc5 frm = new frmQuayveboc5();
                    frm.ShowDialog();
                }
            }
        }
    }
}